const minCostClimbingStairs = cost => {
  let n = cost.length
  let p = 0, q = 0
  for (let i = 2; i <= n; i++) {
    let next = Math.min(q + cost[i - 1], p + cost[i - 2])
    p = q
    q = next
  }
  return q
}

console.log(minCostClimbingStairs([1, 100, 1, 1, 1, 100, 1, 1, 100, 1]));